package com.kaizzi.data.jdl.helper;

import com.kaizzi.data.common.utils.DateUtil;
import com.kaizzi.data.common.utils.JsonUtil;
import com.kaizzi.data.jdl.service.CrmMemberService;
import lombok.Data;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Kzen
 * @Description description
 * @date 2020/9/15
 */
@Component
public class PageData14 {

    @Resource
    private CrmMemberService crmMemberService;

    public String getData(){
        List<String> yearWeeks = DateUtil.getYearWeeks1("2020-01-01 00:00:00");
        Page14 page14 = new Page14();
        List<TempPage> weekList = new ArrayList<>();

        for (String week : yearWeeks) {
            String[] split = week.split("#");
            long userCount = crmMemberService.getUserCount(split[0], split[1], "");
            String date = DateUtil.getDateFormat9(split[0], split[1]);
            TempPage tempPage = new TempPage();
            tempPage.setDate(date);
            tempPage.setUserCount(userCount);
            weekList.add(tempPage);
        }
        page14.setDataPeriod(DateUtil.getFirstDay2LastSunday());
        page14.setWeekData(weekList);
        return JsonUtil.serialize(page14);
    }

//    private List<String> getYearWeeks(String s) {
//        LocalDateTime.parse()
//        return null;
//    }

    @Data
    private static class TempPage{
        private String date;
        private long userCount;
    }

    @Data
    private static class Page14{
        private String dataPeriod;
        private List<TempPage> weekData;
    }
}
